//
//  AttackAbility.m
//  PacIsBack
//
//  Created by Simon André on 12/02/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "AttackAbility.h"
#import "CharacterProtocol.h"
#import "BattleProtocol.h"
#import "BattleViewController.h"
#import "CharacterViewController.h"


@implementation AttackAbility

@synthesize currentSource, currentTarget, currentBattle;

- (NSString*) shownName{
	NSString* name = @"Attack";
	return name;
}

- (NSInteger) mpCost{
	return 0;
}

- (void) executeFrom:(id<CharacterProtocol>)source on:(id<CharacterProtocol>)target inBatte:(id<BattleProtocol>) battle{
	[self setCurrentSource:source];
	[self setCurrentTarget:target];
	[self setCurrentBattle:battle];
	[[battle controller] executeAttackFrom:source toTarget:target];
}

- (void) nextPhase{
	[[self currentSource] setHasPlayed:YES];
}

- (NSInteger) damagesProduced:(id<CharacterProtocol>) source on :(id<CharacterProtocol>) target{
	NSInteger originAttackPower = [source attackPower];
	NSInteger inflictedDamages = [target receiveAttack:originAttackPower];
	NSString* texte = [NSString stringWithFormat:@"%@%@%@%@%d",[source characterType],@" Attack ",[target characterType],@" for ",inflictedDamages];
	[[self currentBattle] showInfo:texte];
	
	return inflictedDamages;
}

- (void) dealloc{
	[self setCurrentBattle:nil];
	[self setCurrentSource:nil];
	[self setCurrentTarget:nil];
	[super dealloc];
}

@end
